home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 36.3 KB | 1,172 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWView.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWVIEW_H
- #include "FWView.h"
- #endif
-
- #ifndef FWSVIEW_H
- #include "FWSView.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWDRGDRP_H
- #include "FWDrgDrp.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWWINDOW_H
- #include "FWWindow.h"
- #endif
-
- #ifndef FWCURSOR_H
- #include "FWCursor.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWAROPER_H
- #include "FWArOper.h"
- #endif
-
- #ifndef FWSOMENV_H
- #include "FWSOMEnv.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwview
- #endif
-
- //========================================================================================
- // class FW_CViewCollection
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CViewCollection)
-
- //========================================================================================
- // class FW_CViewCollectionIterator
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CViewCollectionIterator)
-
- //========================================================================================
- // CLASS FW_CView
- //========================================================================================
-
- FW_DEFINE_CLASS_M1(FW_CView, FW_MEventHandler)
-
- //----------------------------------------------------------------------------------------
- // FW_CView::FW_CView
- //----------------------------------------------------------------------------------------
-
- FW_CView::FW_CView(Environment* ev, FW_CSuperView* container, const FW_CRect& bounds,
- ODID viewID) :
- FW_MEventHandler(ev, container, FW_kNoPriority),
- fViewID(viewID),
- fSuperView(container),
- fBounds(bounds),
- fAdorners(NULL),
- fVisible(TRUE),
- fResizeInvalidates(TRUE),
- fBindings(FW_kFixedLocation + FW_kFixedSize),
- fViewToFrameTransform(NULL),
- fTopPrintedView(FALSE),
- fValidVisibleBounds(FALSE)
- {
- FW_ASSERT(container != NULL);
-
- // add new view to the parent's SubView list
- fSuperView->AddSubView(ev, this);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::FW_CView
- //----------------------------------------------------------------------------------------
-
- FW_CView::FW_CView(Environment* ev) :
- FW_MEventHandler(ev, NULL, FW_kNoPriority),
- fViewID(FW_kNoViewID),
- fSuperView(NULL),
- fBounds(FW_kZeroRect),
- fAdorners(NULL),
- fVisible(TRUE),
- fResizeInvalidates(TRUE),
- fBindings(FW_kFixedLocation + FW_kFixedSize),
- fViewToFrameTransform(NULL),
- fTopPrintedView(FALSE),
- fValidVisibleBounds(FALSE)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::~FW_CView
- //----------------------------------------------------------------------------------------
-
- FW_CView::~FW_CView()
- {
- FW_SOMEnvironment ev;
-
- if (IsTarget(ev))
- {
- FW_Boolean resignedTarget = ResignTarget(ev);
- FW_ASSERT(resignedTarget);
- }
-
- if (fViewToFrameTransform)
- {
- fViewToFrameTransform->Release(ev);
- fViewToFrameTransform = NULL;
- }
-
- if (fSuperView != NULL)
- fSuperView->RemoveSubView(ev, this);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::SetViewID
- //----------------------------------------------------------------------------------------
- void FW_CView::SetViewID(Environment* ev, ODID id)
- {
- FW_UNUSED(ev);
- fViewID = id;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::FindViewByID
- //----------------------------------------------------------------------------------------
-
- FW_CView* FW_CView::FindViewByID(Environment* ev, ODID requestedID) const
- {
- FW_UNUSED(ev);
-
- if (fViewID == requestedID)
- return (FW_CView*)this; // cast away const
- else
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::IsContentView
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::IsContentView(Environment* ev) const
- {
- FW_UNUSED(ev);
- // only super views can be content views
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::Invalidate
- //----------------------------------------------------------------------------------------
- // rect is in content coordinates
-
- void FW_CView::Invalidate(Environment* ev, const FW_CRect& rect, FW_Boolean allFrames)
- {
- if (fVisible)
- {
- FW_CAcquiredODShape aqInvalidShape = ::FW_NewODShape(ev, rect);
- FW_CFrame* frame = GetFrame(ev);
- if (allFrames)
- frame->GetPresentation(ev)->Invalidate(ev, aqInvalidShape, frame->GetSequenceNumber(ev));
- else
- {
- ViewContentToFrame(ev, aqInvalidShape);
- frame->GetODFrame(ev)->Invalidate(ev, aqInvalidShape, NULL);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::Validate
- //----------------------------------------------------------------------------------------
- // rect is in content coordinates
-
- void FW_CView::Validate(Environment* ev, const FW_CRect& rect, FW_Boolean allFrames)
- {
- if (fVisible)
- {
- FW_CAcquiredODShape aqValidShape = ::FW_NewODShape(ev, rect);
- FW_CFrame* frame = GetFrame(ev);
- if (allFrames)
- frame->GetPresentation(ev)->Validate(ev, aqValidShape, frame->GetSequenceNumber(ev));
- else
- {
- ViewContentToFrame(ev, aqValidShape);
- frame->GetODFrame(ev)->Validate(ev, aqValidShape, NULL);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::Invalidate
- //----------------------------------------------------------------------------------------
- // invalidShape is in content coordinates
-
- void FW_CView::Invalidate(Environment* ev, ODShape* invalidShape, FW_Boolean allFrames)
- {
- if (fVisible) {
- if (invalidShape == NULL)
- {
- FW_CRect bounds = GetBoundsInContent(ev);
- Invalidate(ev, bounds, allFrames);
- }
- else
- {
- FW_CFrame* frame = GetFrame(ev);
- if (allFrames)
- frame->GetPresentation(ev)->Invalidate(ev, invalidShape, frame->GetSequenceNumber(ev));
- else
- {
- FW_CAcquiredODShape aCopy = invalidShape->Copy(ev);
- ViewContentToFrame(ev, aCopy);
- frame->GetODFrame(ev)->Invalidate(ev, aCopy, NULL);
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::Validate
- //----------------------------------------------------------------------------------------
- // invalidShape is in content coordinates
-
- void FW_CView::Validate(Environment* ev, ODShape* validShape, FW_Boolean allFrames)
- {
- if (fVisible) {
- if (validShape == NULL)
- {
- FW_CRect bounds = GetBoundsInContent(ev);
- Validate(ev, bounds, allFrames);
- }
- else
- {
- FW_CFrame* frame = GetFrame(ev);
- if (allFrames)
- frame->GetPresentation(ev)->Validate(ev, validShape, frame->GetSequenceNumber(ev));
- else
- {
- FW_CAcquiredODShape aCopy = validShape->Copy(ev);
- ViewContentToFrame(ev, aCopy);
- frame->GetODFrame(ev)->Validate(ev, aCopy, NULL);
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::GetBoundsInContent
- //----------------------------------------------------------------------------------------
- // returns the bounds in content coordinates
-
- FW_CRect FW_CView::GetBoundsInContent(Environment *ev) const
- {
- FW_CRect bounds = GetBounds(ev);
- bounds.Place(FW_kFixed0, FW_kFixed0);
- return bounds;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::AdjustCursor
- //----------------------------------------------------------------------------------------
- // where is in frame coordinate
-
- FW_Handled FW_CView::AdjustCursor(Environment *ev, ODFacet* odFacet, const FW_CPoint& theMousePoint, ODEventInfo* eventInfo)
- {
- // [LSD] ok?
- return fSuperView ? fSuperView->AdjustCursor(ev, odFacet, theMousePoint, eventInfo) : FW_kNotHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::IsSubViewOf
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::IsSubViewOf(Environment* ev, const FW_CSuperView* parentView) const
- {
- if (fSuperView == NULL)
- return FALSE;
- else if (fSuperView == parentView)
- return TRUE;
- else
- return fSuperView->IsSubViewOf(ev, parentView);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::HasSubViews
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::HasSubViews(Environment* ev) const
- {
- FW_UNUSED(ev);
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::IsMouseWithin
- //----------------------------------------------------------------------------------------
- // theMousePoint is in frame coordinate
-
- FW_Boolean FW_CView::IsMouseWithin(Environment* ev, ODFacet* odFacet, const FW_CPoint& theMousePoint) const
- {
- // We get a NULL facet when clicking outside a modal dialog box.
- if (odFacet == NULL)
- return FALSE;
-
- FW_CPoint where(theMousePoint);
- FrameToView(ev, where);
-
- return FW_CRect(FW_kZeroPoint, GetSize(ev)).Contains(where);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::GetViewContaining
- //----------------------------------------------------------------------------------------
- // Find the visible & enabled view containing a point (in frame coordinates)
-
- FW_CView* FW_CView::GetViewContaining(Environment* ev, ODFacet* odFacet,
- const FW_CPoint& theMousePoint)
- {
- if (fVisible && IsEnabled(ev) && IsMouseWithin(ev, odFacet, theMousePoint))
- return this;
- else
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::SetLocation
- //----------------------------------------------------------------------------------------
-
- void FW_CView::SetLocation(Environment* ev, const FW_CPoint& location, FW_ERedrawVerb redraw)
- {
- FW_CPoint oldLocation = fBounds.TopLeft();
-
- if (oldLocation != location)
- {
- if (redraw == FW_kInvalidate)
- Invalidate(ev, NULL);
-
- fBounds.right = location.x + (fBounds.right - fBounds.left);
- fBounds.bottom = location.y + (fBounds.bottom - fBounds.top);
- fBounds.left = location.x;
- fBounds.top = location.y;
-
- PrivInvalidateCachedTransforms(ev);
-
- LocationChanged(ev, oldLocation); // used by controls on Windows
-
- if (redraw == FW_kInvalidate)
- Invalidate(ev, NULL);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::LocationChanged
- //----------------------------------------------------------------------------------------
-
- void FW_CView::LocationChanged(Environment* ev, const FW_CPoint& oldLocation)
- {
- FW_UNUSED(oldLocation);
-
- PrivInvalidateVisibleBounds(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::SetSize
- //----------------------------------------------------------------------------------------
-
- void FW_CView::SetSize(Environment* ev, const FW_CPoint& size, FW_ERedrawVerb redraw)
- {
- FW_CPoint oldSize = fBounds.Size();
- if (oldSize != size)
- {
- if ((redraw == FW_kInvalidate) && fResizeInvalidates)
- Invalidate(ev, NULL); // refresh old bounds
-
- // Change the bounds
- fBounds.right = fBounds.left + size.x;
- fBounds.bottom = fBounds.top + size.y;
-
- SizeChanged(ev, oldSize); // used by controls on Windows
-
- if (redraw == FW_kInvalidate)
- {
- if (fResizeInvalidates)
- Invalidate(ev, NULL); // refresh new bounds
- else
- {
- // Invalidate only the region that changed (optimization for views whose
- // content appearance doesn't depend on its size).
-
- FW_CRect oldBounds(FW_kZeroPoint, oldSize);
- FW_CRect newBounds(FW_kZeroPoint, size);
-
- FW_CAcquiredODShape aqOldShape = ::FW_NewODShape(ev, oldBounds);
- aqOldShape->SetGeometryMode(ev, kODLoseGeometry);
-
- FW_CAcquiredODShape aqNewShape = ::FW_NewODShape(ev, newBounds);
- aqNewShape->SetGeometryMode(ev, kODLoseGeometry);
-
- FW_CAcquiredODShape aqUnionShape = aqOldShape->Copy(ev);
- aqUnionShape->SetGeometryMode(ev, kODLoseGeometry);
-
- aqUnionShape->Union(ev, aqNewShape);
- aqOldShape->Intersect(ev, aqNewShape);
- aqUnionShape->Subtract(ev, aqOldShape);
-
- // Shape must be converted to frame coordinates before calling Invalidate
- ViewToFrame(ev, aqUnionShape);
-
- GetFrame(ev)->GetODFrame(ev)->Invalidate(ev, aqUnionShape, NULL);
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::SizeChanged
- //----------------------------------------------------------------------------------------
-
- void FW_CView::SizeChanged(Environment* ev, const FW_CPoint& oldSize)
- {
- FW_UNUSED(oldSize);
-
- PrivInvalidateVisibleBounds(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::IsVisible
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::IsVisible(Environment* ev) const
- {
- // If my parent is not visible I am also not visible
- return fVisible && (fSuperView != NULL ? fSuperView->IsVisible(ev) : TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::PrivInvalidateCachedTransforms
- //----------------------------------------------------------------------------------------
-
- void FW_CView::PrivInvalidateCachedTransforms(Environment* ev)
- {
- // Note: I am not invalidating my visible bounds but the visible bounds of
- // my subviews. See FW_CSuperView::PrivInvalidateCachedTransforms
-
- if (fViewToFrameTransform)
- {
- fViewToFrameTransform->Release(ev);
- fViewToFrameTransform = NULL;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::AdjustToNewLayout
- //----------------------------------------------------------------------------------------
- // Simple layout management based on 6 binding flags (or rubber bands)
- //
- // +-------------------------------------------+
- // | | |
- // | Top Binding? |... SuperView whose extent changed
- // | | | from oldExtent to newExtent
- // | +-------------------+ |
- // | | | |...........|... View being adjusted
- // | | | | |
- // |<--Left--->|<--Fixed--+------->|<--Right-->|
- // | Binding? | Width? | | Binding? |
- // | | | | |
- // | | Fixed Height? | |
- // | | | | |
- // | +-------------------+ |
- // | | |
- // | Bottom Binding? |
- // | | |
- // +-------------------------------------------+
- //
-
- void FW_CView::AdjustToNewLayout(Environment *ev,
- const FW_CPoint& oldExtent,
- const FW_CPoint& newExtent,
- FW_ERedrawVerb redraw)
- {
- // Nothing to do if view is fixed in size and position
- if ((fBindings & FW_kLeftBinding) && (fBindings & FW_kFixedWidth) &&
- (fBindings & FW_kTopBinding) && (fBindings & FW_kFixedHeight))
- return;
-
- FW_Fixed deltaWidth = newExtent.x - oldExtent.x;
- FW_Fixed deltaWidth2 = FW_Half(deltaWidth);
- FW_Fixed deltaHeight = newExtent.y - oldExtent.y;
- FW_Fixed deltaHeight2 = FW_Half(deltaHeight);
- FW_CRect bounds = GetBounds(ev);
- FW_Fixed width = bounds.right - bounds.left;
- FW_Fixed height = bounds.bottom - bounds.top;
-
- // Note: we don't check for errors when all 3 bindings are set horizontally
- // or vertically. In this case we ignore FW_kRightBinding & FW_kBottomBinding
-
- // ----- Horizontal adjustement
-
- if (fBindings & FW_kLeftBinding)
- {
- // left edge doesn't move
- // right edge moves only if the width is not fixed
- if (fBindings & FW_kRightBinding)
- {
- // right edge moves by the same amount
- bounds.right += deltaWidth;
- }
- else if (!(fBindings & FW_kFixedWidth))
- {
- // width is not fixed so right edge moves proportionally
- bounds.right = bounds.left +
- (width / (oldExtent.x - bounds.left)) * (newExtent.x - bounds.left);
- }
- }
- else
- {
- if (fBindings & FW_kRightBinding)
- {
- // right edge moves by the same amount
- bounds.right += deltaWidth;
-
- if (fBindings & FW_kFixedWidth) {
- // width is fixed so left edge moves by the same amount
- bounds.left += deltaWidth;
- }
- else
- {
- // width is not fixed so left edge moves proportionally
- bounds.left = (bounds.left / (bounds.left + width)) * bounds.right;
- }
- }
- else
- {
- // both left and right edges move proportionally
- bounds.left = (bounds.left / oldExtent.x) * newExtent.x;
- if (fBindings & FW_kFixedWidth)
- bounds.right = bounds.left + width;
- else
- bounds.right = (bounds.right / oldExtent.x) * newExtent.x;
- }
- }
-
- // ----- Vertical adjustement
-
- if (fBindings & FW_kTopBinding)
- {
- if (fBindings & FW_kBottomBinding)
- bounds.bottom += deltaHeight;
- else if (!(fBindings & FW_kFixedHeight))
- bounds.bottom = bounds.top +
- (height / (oldExtent.y - bounds.top)) * (newExtent.y - bounds.top);
- }
- else
- {
- if (fBindings & FW_kBottomBinding)
- {
- bounds.bottom += deltaHeight;
-
- if (fBindings & FW_kFixedHeight)
- bounds.top += deltaHeight;
- else
- bounds.top = (bounds.top / (bounds.top + height)) * bounds.bottom;
- }
- else
- {
- bounds.top = (bounds.top / oldExtent.y) * newExtent.y;
- if (fBindings & FW_kFixedHeight)
- bounds.bottom = bounds.top + height;
- else
- bounds.bottom = (bounds.bottom / oldExtent.y) * newExtent.y;
- }
- }
-
- // ----- We're done. Adjust location and size (SetSize may in turn adjust subviews)
- SetLocation(ev, bounds.TopLeft(), redraw);
- SetSize(ev, bounds.Size(), redraw);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::AcquireViewToFrameTransform
- //----------------------------------------------------------------------------------------
- // returns the transform to convert view coordinates to frame coordinates
-
- ODTransform* FW_CView::AcquireViewToFrameTransform(Environment* ev) const
- {
- FW_CView* self = (FW_CView*)this;
-
- if (fViewToFrameTransform == NULL)
- {
- FW_CPoint location = GetLocation(ev);
- self->fViewToFrameTransform = ::FW_NewODTransform(ev, location);
-
- if (fSuperView != NULL)
- {
- FW_CAcquiredODTransform aqViewContentTransform = fSuperView->AcquireViewContentToFrameTransform(ev);
- self->fViewToFrameTransform->PostCompose(ev, aqViewContentTransform);
- }
- }
-
- self->fViewToFrameTransform->Acquire(ev);
-
-
- return fViewToFrameTransform;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::AcquireViewContentToFrameTransform
- //----------------------------------------------------------------------------------------
- // returns the transform to convert view content coordinates to frame coordinates
-
- ODTransform* FW_CView::AcquireViewContentToFrameTransform(Environment* ev) const
- {
- return FW_CView::AcquireViewToFrameTransform(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::PrivInvalidateViewIternalTransform
- //----------------------------------------------------------------------------------------
-
- void FW_CView::PrivInvalidateViewIternalTransform(Environment* ev)
- {
- FW_UNUSED(ev);
- // Noting to do: can't scroll can't scale
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::FrameToViewContent
- //----------------------------------------------------------------------------------------
-
- void FW_CView::FrameToViewContent(Environment *ev, FW_CPoint& point) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));
- point.InverseTransform(ev, aqViewToFrameTransform);
- }
-
- void FW_CView::FrameToViewContent(Environment *ev, FW_CRect& rect) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));
- rect.InverseTransform(ev, aqViewToFrameTransform);
- }
-
- void FW_CView::FrameToViewContent(Environment *ev, ODShape* shape) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));
- shape->InverseTransform(ev, aqViewToFrameTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::ViewContentToFrame
- //----------------------------------------------------------------------------------------
-
- void FW_CView::ViewContentToFrame(Environment *ev, FW_CPoint& point) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));
- point.Transform(ev, aqViewToFrameTransform);
- }
-
- void FW_CView::ViewContentToFrame(Environment *ev, FW_CRect& rect) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));
- rect.Transform(ev, aqViewToFrameTransform);
- }
-
- void FW_CView::ViewContentToFrame(Environment *ev, ODShape* shape) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));
- shape->Transform(ev, aqViewToFrameTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::FrameToView
- //----------------------------------------------------------------------------------------
-
- void FW_CView::FrameToView(Environment *ev, FW_CPoint& point) const
- {
- if (IsFrame(ev) == FALSE) {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));
- point.InverseTransform(ev, aqViewToFrameTransform);
- }
- }
-
- void FW_CView::FrameToView(Environment *ev, FW_CRect& rect) const
- {
- if (IsFrame(ev) == FALSE) {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));
- rect.InverseTransform(ev, aqViewToFrameTransform);
- }
- }
-
- void FW_CView::FrameToView(Environment *ev, ODShape* shape) const
- {
- if (IsFrame(ev) == FALSE) {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));
- shape->InverseTransform(ev, aqViewToFrameTransform);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::ViewToFrame
- //----------------------------------------------------------------------------------------
-
- void FW_CView::ViewToFrame(Environment *ev, FW_CPoint& point) const
- {
- if (IsFrame(ev) == FALSE) {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));
- point.Transform(ev, aqViewToFrameTransform);
- }
- }
-
- void FW_CView::ViewToFrame(Environment *ev, FW_CRect& rect) const
- {
- if (IsFrame(ev) == FALSE) {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));
- rect.Transform(ev, aqViewToFrameTransform);
- }
- }
-
- void FW_CView::ViewToFrame(Environment *ev, ODShape* shape) const
- {
- if (IsFrame(ev) == FALSE) {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));
- shape->Transform(ev, aqViewToFrameTransform);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::GetFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* FW_CView::GetFrame(Environment* ev) const
- {
- FW_CSuperView* superView = GetSuperView(ev);
- return (superView ? superView->GetFrame(ev) : NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::IsFrame
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::IsFrame(Environment* ev) const
- {
- FW_UNUSED(ev);
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::HandleMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Handled FW_CView::HandleMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_Handled handled = FW_kNotHandled;
- FW_CFrame* frame = GetFrame(ev);
-
- if ((frame->IsRoot(ev) == FALSE) && frame->ActivateWindow(ev, theMouseEvent.GetFacet(ev), TRUE))
- return FW_kHandled; // didn't want the first click on non-active frame
-
- if (frame->GetWindow(ev)->IsActive(ev))
- {
- if (this->WantsToBeTarget(ev))
- {
- // Must be sure target's frame is active, else key events won't get there
- // (handles case of root frame containing an active embedded frame)
- frame->ActivateFrame(ev, theMouseEvent.GetFacet(ev));
-
- this->BecomeTarget(ev);
- }
-
- handled = FW_MEventHandler::HandleMouseDown(ev, theMouseEvent);
- }
-
- return handled;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::HandleBGMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Handled FW_CView::HandleBGMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_CFrame* frame = GetFrame(ev);
- FW_ASSERT(frame);
-
- FW_CSelection* selection = frame->GetPresentation(ev)->GetSelection(ev);
- if (selection)
- selection->UpdateSelectionOnMouseDown(ev, theMouseEvent, NULL, FALSE, TRUE);
-
- return FW_MEventHandler::HandleBGMouseDown(ev, theMouseEvent);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::DoBGMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Handled FW_CView::DoBGMouseDown(Environment *ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_CFrame* frame = GetFrame(ev);
- FW_ASSERT(frame);
-
- FW_CSelection* selection = frame->GetPresentation(ev)->GetSelection(ev);
- if (selection != NULL && selection->IsMouseInDraggableItem(ev, frame, theMouseEvent, TRUE))
- {
- FW_MDraggableFrame* draggable = frame->GetDraggable(ev);
- if (draggable && draggable->Drag(ev, theMouseEvent))
- return FW_kHandled;
- }
-
- // return FW_kNotHandled because I am not doing anything. Let the process manager do its job.
- return FW_kNotHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::HandleMouseUp
- //----------------------------------------------------------------------------------------
-
- FW_Handled FW_CView::HandleMouseUp(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_CFrame* frame = GetFrame(ev);
- FW_ASSERT(frame);
-
- frame->ActivateFrame(ev, theMouseEvent.GetFacet(ev)); // Will test if it can be the activeframe
-
- return FW_MEventHandler::HandleMouseUp(ev, theMouseEvent);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::DoMouseEnter
- //----------------------------------------------------------------------------------------
-
- FW_Handled FW_CView::DoMouseEnter(Environment* ev, ODFacet* odFacet, const FW_CPoint& theMousePoint, ODEventInfo* eventInfo)
- {
- FW_UNUSED(ev);
- FW_UNUSED(odFacet);
- FW_UNUSED(theMousePoint);
- FW_UNUSED(eventInfo);
-
- return FW_kNotHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::DoMouseWithin
- //----------------------------------------------------------------------------------------
-
- FW_Handled FW_CView::DoMouseWithin(Environment* ev, ODFacet* odFacet, const FW_CPoint& theMousePoint, ODEventInfo* eventInfo)
- {
- FW_UNUSED(ev);
- FW_UNUSED(odFacet);
- FW_UNUSED(theMousePoint);
- FW_UNUSED(eventInfo);
-
- return FW_kNotHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::DoMouseLeave
- //----------------------------------------------------------------------------------------
-
- FW_Handled FW_CView::DoMouseLeave(Environment* ev, ODFacet* odFacet, ODEventInfo* eventInfo)
- {
- FW_UNUSED(ev);
- FW_UNUSED(odFacet);
- FW_UNUSED(eventInfo);
-
- return FW_kNotHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::HandleActivateEvent
- //----------------------------------------------------------------------------------------
-
- void FW_CView::HandleActivateEvent(Environment* ev, const FW_CActivateEvent& theActivateEvent)
- {
- DoActivateEvent(ev, theActivateEvent);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::DoActivateEvent
- //----------------------------------------------------------------------------------------
-
- void FW_CView::DoActivateEvent(Environment* ev, const FW_CActivateEvent& theActivateEvent)
- {
- FW_UNUSED(ev);
- FW_UNUSED(theActivateEvent);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::GetExtent
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CView::GetExtent(Environment* ev) const
- {
- FW_UNUSED(ev);
- return fBounds.Size();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::GetVisibleBounds
- //----------------------------------------------------------------------------------------
- // Returns the visible bounds of the view through all its superviews (in frame coordinate).
- // The cached visible bounds is invalidated when this view size or location change (bounds)
- // and when its superview ViewContentToFrame transform is invalidated
-
- FW_CRect FW_CView::GetVisibleBounds(Environment *ev) const
- {
- if (!fValidVisibleBounds)
- {
- FW_CView* self = (FW_CView*)this;
- FW_CView* aView = self;
- FW_CFrame* frame = self->GetFrame(ev);
- self->fVisibleBounds = frame->GetBounds(ev);
-
- // go up superview chain and stop at the frame
- while (aView != frame && !fVisibleBounds.IsEmpty())
- {
- FW_CRect bounds = aView->GetBounds(ev);
-
- FW_CSuperView* superView = aView->fSuperView;
- if (superView)
- superView->ViewContentToFrame(ev, bounds);
-
- self->fVisibleBounds.Intersection(bounds);
-
- aView = superView;
- }
-
- self->fValidVisibleBounds = TRUE;
- }
-
- return fVisibleBounds;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::PrivInvalidateVisibleBounds
- //----------------------------------------------------------------------------------------
-
- void FW_CView::PrivInvalidateVisibleBounds(Environment *ev)
- {
- FW_UNUSED(ev);
-
- fValidVisibleBounds = FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::HandleDraw
- //----------------------------------------------------------------------------------------
- // invalidShape is in frame coordinate
-
- FW_Handled FW_CView::HandleDraw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- FW_Handled handled = FW_kNotHandled;
-
- if (fVisible)
- {
- // [LSD] todo: handle tri-state visibility
- // [LSD] todo: Draw high-priority adorners
-
- FW_CRect visiblebounds = GetVisibleBounds(ev); // return in frame coordinate
- if (!visiblebounds.IsEmpty())
- {
- FW_CAcquiredODShape aqInvalidShape = ::FW_NewODShape(ev, visiblebounds);
- aqInvalidShape->SetGeometryMode(ev, kODLoseGeometry);
-
- if (invalidShape)
- aqInvalidShape->Intersect(ev, invalidShape);
-
- if (!aqInvalidShape->IsEmpty(ev))
- {
- FrameToViewContent(ev, aqInvalidShape);
- Draw(ev, odFacet, aqInvalidShape);
- handled = FW_kHandled;
- }
- }
-
- // [LSD] todo: Draw low-priority adorners
- }
-
- return handled;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::Draw
- //----------------------------------------------------------------------------------------
- // invalidShape is in content coordinate of this view
-
- void FW_CView::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- FW_UNUSED(ev);
- FW_UNUSED(odFacet);
- FW_UNUSED(invalidShape);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::SetVisible
- //----------------------------------------------------------------------------------------
-
- void FW_CView::SetVisible(Environment* ev, FW_Boolean visible, FW_Boolean propagate)
- {
- FW_UNUSED(ev);
- FW_UNUSED(propagate);
- // Not allowed to make the Frame invisible!
- FW_ASSERT(IsFrame(ev) == FALSE || visible == TRUE);
-
- if (fVisible != visible)
- {
- // [HLX] Because Invalidate test for fVisible it needs to be done in the right order
- if (fVisible)
- {
- Invalidate(ev, NULL, false);
- fVisible = visible; // hide
- }
- else
- {
- fVisible = visible; // show
- Invalidate(ev, NULL, false);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::PrivAcquireContentScrollShape
- //----------------------------------------------------------------------------------------
-
- void FW_CView::PrivAcquireContentScrollShape(Environment* ev,
- FW_XYSelector direction,
- ODShape* scrollShape) const
- {
- FW_UNUSED(ev);
- FW_UNUSED(direction);
- FW_UNUSED(scrollShape);
- // nothing to do: can't scroll, can't have subviews
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::Write
- //----------------------------------------------------------------------------------------
-
- void FW_CView::Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object)
- {
- FW_UNUSED(type);
- FW_SOMEnvironment ev;
- ((const FW_CView *) object)->Flatten(ev, stream);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::Read
- //----------------------------------------------------------------------------------------
-
- void FW_CView::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type, void* object)
- {
- FW_UNUSED(type);
- FW_SOMEnvironment ev;
- ((FW_CView *) object)->InitializeFromStream(ev, stream);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CView::Flatten(Environment* ev, FW_CWritableStream& stream) const
- {
- FW_UNUSED(ev);
-
- FW_CSuperView* superView = fSuperView;
- FW_WRITE_DYNAMIC_OBJECT(stream, superView, FW_CSuperView);
-
- stream << fViewID;
- stream << fBounds;
- stream << fBindings;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::InitializeFromStream
- //----------------------------------------------------------------------------------------
-
- void FW_CView::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
- {
- FW_READ_DYNAMIC_OBJECT(stream, &fSuperView, FW_CSuperView);
- SetNextEventHandler(ev, fSuperView);
-
- // [JEL] Currently, FW_MEventHandler's are not archivable. This means that FW_CView must
- // properly initialize the inherited FW_MEventHandler. The NextEventHandler field
- // is easily done, but what about the priority? Should every view resource have a
- // priority field? For now we punt and set the priority to FW_kNoPriority.
- SetPriority(ev, FW_kNoPriority);
-
- stream >> fViewID;
- stream >> fBounds;
- stream >> fBindings;
-
- FW_ASSERT(fBounds.left < fBounds.right && fBounds.top < fBounds.bottom);
-
- // add new view to the parent's SubView list
- if (fSuperView)
- fSuperView->AddSubView(ev, this);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::PostCreateViewFromStream
- //----------------------------------------------------------------------------------------
-
- void FW_CView::PostCreateViewFromStream(Environment* ev)
- {
- FW_UNUSED(ev);
- // Nothing to do
- // Subclasses of Views that cache references to other objects
- // or otherwise maintain state that cannot be initialized from a
- // stream will need to update that state information by
- // overriding this method. FW_CSuperView must propogate
- // this message to every subview.
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::PrivPostCreateViewFromStream
- //----------------------------------------------------------------------------------------
-
- void FW_CView::PrivPostCreateViewFromStream(Environment* ev)
- {
- // Handle this view first
- PostCreateViewFromStream(ev);
- }
-
-